<?php
namespace app\base\controller;
use framework\base\Config;
class BaseController extends \framework\base\Controller{
	
    public function __construct(){
        define('APP_PATH', ROOT_PATH . 'app' . DIRECTORY_SEPARATOR);  //APP目录
        define('DATA_PATH', ROOT_PATH . 'data' . DIRECTORY_SEPARATOR); //缓存目录
        define('__PUBLIC__', substr(PUBLIC_URL, 0, -1));  //附件目录
        define('__ROOT__', substr(ROOT_URL, 0, -1)); //系统网址
        defined('__TPL__') or define('__TPL__', ROOT_URL .'themes/');  //前台模板目录
        include_once(APP_PATH . 'base/lib/function.php');   //引入函数
        config(APP_NAME, require(BASE_PATH.'app/'.APP_NAME.'/config.php'));
    }

   //分页结果显示
    protected function getPage($pager,$action = array()){
        $pageArray = $pager;
        if(is_array($pageArray)){
	        $html = '<ul class="pager"><li><a href="'.$this->GreatePageUrl($pageArray['firstPage'],$action).'" >首页</a></li>
	                <li><a href="'.$this->GreatePageUrl($pageArray['prevPage'],$action).'">上一页</a></li> ';
	            foreach ($pageArray['allPages'] as $value) {
                    if($value){
    	                if($value == $pageArray['page']){
    	                    $html .= '<li class="active">';
    	                }else{
    	                    $html .= '<li>';
    	                }
                        $html .= '<a href="'.$this->GreatePageUrl($value,$action).'">'.$value.'</a></li>';
                    }        
	           }
	         $html .= '<li><a href="'.$this->GreatePageUrl($pageArray['nextPage'],$action).'">下一页</a></li>
	          <li><a href="'.$this->GreatePageUrl($pageArray['lastPage'],$action).'">末页</a></li></ul>';
        }
        return $html;
    }

    //分页URL处理
    public function GreatePageUrl($page,$action = array()){
        $ary_page = array('page' => $page);
        if($action){
            $ary_page = array_merge($ary_page,$action);
        }
        return url( APP_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME,$ary_page);
    }
}